package com.portal.back.web;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import com.opensymphony.xwork2.ActionContext;
import com.portal.back.service.ISysProfessionalService;
import com.portal.back.service.impl.SysProfessionalService;
import com.portal.base.web.BaseAction;
import com.portal.domain.SysProfessional;
import com.portal.util.common.CharacterUtil;
/**
 * @Title:行业视点类别Action
 * @Copyright: Copyright (c) 0.1
 * @author:鲁根成
 * @version: 1.0
 * @time: 2011-4-13
 * 
 */
@SuppressWarnings("serial")
public class SysProfessionalAction extends BaseAction {
	private ISysProfessionalService service;
	private SysProfessional professional;

	public SysProfessional getProfessional() {
		return professional;
	}

	/*
	 * 增加类别
	 */
	public String addProfessional() {

		professional.setTitle(CharacterUtil.encode(professional.getTitle()));
		professional.setDescribe(CharacterUtil.encode(professional
				.getDescribe()));
		boolean isFlag = service.addProfession(professional);
		if (isFlag)
			return "success";
		else
			return "error";

	}

	/**
	 * 获得所有类别信息
	 * 
	 */
	public String getAllPro() {
		List<SysProfessional> list = service.getAllPro();
		ActionContext context = ActionContext.getContext();
		context.put("list", list);
		return "getAllpro";
	}

	public String deletePro() {
		String deleteByIdString = request.getParameter("id");
		boolean isFlag = service.deleteById(deleteByIdString);
		response.setContentType("text/html;charset=gbk");
		PrintWriter out = null;
		if (isFlag)
			message = "删除成功";
		else
			message = "删除失败";
		StringBuffer sb = new StringBuffer("[");
		sb.append("{\"message\":\"" + message + "\"" + "}");
		sb.append("]");

		try {
			out = response.getWriter();
			out.println(sb.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;

	}

	public String getProById() {
		String id = request.getParameter("id");
		SysProfessional pro = service.getById(id);
		ActionContext context = ActionContext.getContext();
		context.put("pro", pro);
		return "somepro";
	}

	public void setProfessional(SysProfessional professional) {
		this.professional = professional;
	}

	public SysProfessionalAction() {
		service = new SysProfessionalService();
	}
}
